import os,django,time
from datetime import datetime,date,timedelta
from loguru import logger
from django.utils import timezone
import tkinter as tk
from tkinter import messagebox
os.environ.setdefault('DJANGO_SETTINGS_MODULE','application.settings')
django.setup()

from apps.website.models import Website
from apps.prescription.handler import atmtorad,writelog,writeServicelog
from apps.prescription.hisinfo import multi_processgethisinfo
from conf.env import AUTO_SERVE,SLEEP_TIME_SECOND

def autoserve():
    m, n = 0, 0
    while True:
        n += 1
        if n > 10 :
            n = 1
            msg = " 服务运行中"
            writeServicelog(msg)
            five_minutes_ago = timezone.now() - timedelta(minutes=5)
            atmtorad(five_minutes_ago=five_minutes_ago)

        multi_processgethisinfo()
        time.sleep(SLEEP_TIME_SECOND)

if __name__ == '__main__':
    if AUTO_SERVE:
        autoserve()
